use [hanhuddb]
GO
IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.ArticleCategories_GetCategoryTitle') AND TYPE IN (N'FN') ))
	DROP FUNCTION dbo.ArticleCategories_GetCategoryTitle
GO
CREATE FUNCTION dbo.ArticleCategories_GetCategoryTitle
(
	@CategoryID		INT 
) RETURNS NVARCHAR(4000)
AS
BEGIN
	DECLARE @parentId INT 
	DECLARE @CategoryTitle nvarchar(4000)
	SELECT @CategoryTitle = Title , @parentId = ParentArticleCategoryID from ArticleCategories where ArticleCategoryID = @CategoryID
	WHILE(@parentId is not null)
		SELECT @CategoryTitle = Title + N', ' + @CategoryTitle , @parentId = ParentArticleCategoryID from ArticleCategories where ArticleCategoryID = @parentId
	--print @url
	RETURN @CategoryTitle
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.ArticleCategories_GetCategoryInfo') AND type IN (N'P', N'PC')))
	DROP PROCEDURE dbo.ArticleCategories_GetCategoryInfo
GO
CREATE PROCEDURE dbo.ArticleCategories_GetCategoryInfo
	@ArticleCategoryID		INT 
AS
BEGIN
	SELECT c.ArticleCategoryID, ISNULL(c.ParentArticleCategoryID, -1) AS ParentArticleCategoryID
	, c.AddedDate, c.Title, c.[Description], c.IsPrivate, c.AllowedRoles
	FROM ArticleCategories c WHERE c.ArticleCategoryID = @ArticleCategoryID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.ArticleCategories_GetAllCategories') AND type IN (N'P', N'PC')))
	DROP PROCEDURE dbo.ArticleCategories_GetAllCategories
GO
CREATE PROCEDURE dbo.ArticleCategories_GetAllCategories
AS
BEGIN
	;WITH ArticleCategoriesCTE(ArticleCategoryID, ParentArticleCategoryID, AddedDate, Title, [Description], IsPrivate, AllowedRoles)
	AS
	(
		SELECT c.ArticleCategoryID, ISNULL(c.ParentArticleCategoryID, -1) AS ParentArticleCategoryID, c.AddedDate, c.Title, c.[Description], c.IsPrivate, c.AllowedRoles
		FROM ArticleCategories c 
		WHERE 
			c.ParentArticleCategoryID IS NULL
		
		UNION ALL
		
		SELECT c.ArticleCategoryID, ISNULL(c.ParentArticleCategoryID, -1) AS ParentArticleCategoryID, c.AddedDate, c.Title, c.[Description], c.IsPrivate, c.AllowedRoles
		FROM ArticleCategories AS c INNER JOIN
			ArticleCategoriesCTE AS ac ON c.ParentArticleCategoryID = ac.ArticleCategoryID
	)
	
	SELECT ArticleCategoryID, ParentArticleCategoryID, AddedDate, Title, [Description], IsPrivate, AllowedRoles
	FROM ArticleCategoriesCTE
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.ArticleCategories_GetCategoryInfo') AND type IN (N'P', N'PC')))
	DROP PROCEDURE dbo.ArticleCategories_GetCategoryInfo
GO
CREATE PROCEDURE dbo.ArticleCategories_GetCategoryInfo
	@ArticleCategoryID	INT
AS
BEGIN
	;WITH ArticleCategoriesCTE(ArticleCategoryID, ParentArticleCategoryID, AddedDate, Title, [Description], IsPrivate, AllowedRoles)
	AS
	(
		SELECT c.ArticleCategoryID, ISNULL(c.ParentArticleCategoryID, -1) AS ParentArticleCategoryID, c.AddedDate, c.Title, c.[Description], c.IsPrivate, c.AllowedRoles
		FROM ArticleCategories c 
		WHERE 
			c.ArticleCategoryID = @ArticleCategoryID
		
		UNION ALL
		
		SELECT c.ArticleCategoryID, ISNULL(c.ParentArticleCategoryID, -1) AS ParentArticleCategoryID, c.AddedDate, c.Title, c.[Description], c.IsPrivate, c.AllowedRoles
		FROM ArticleCategories AS c INNER JOIN
			ArticleCategoriesCTE AS ac ON c.ParentArticleCategoryID = ac.ArticleCategoryID
	)
	
	SELECT ArticleCategoryID, ParentArticleCategoryID, AddedDate, Title, [Description], IsPrivate, AllowedRoles
	FROM ArticleCategoriesCTE
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_UpdateCategory') AND type IN (N'P', N'PC')))
	DROP PROCEDURE dbo.Articles_UpdateCategory
GO
CREATE PROCEDURE dbo.Articles_UpdateCategory
(
	@CategoryID		INT ,
	@parentId		INT ,
	@AddedDate		DATETIME,
	@Title			nvarchar(256),
	@Description	nvarchar(500),
	@IsPrivate		bit
)
AS
BEGIN
	IF(@parentId <= 0) SET @parentId = NULL
	UPDATE ArticleCategories SET
		ParentArticleCategoryID	= @parentId,
		AddedDate				= @AddedDate,
		Title					= @Title,
		Description				= @Description,
		IsPrivate				= @IsPrivate
	WHERE ArticleCategoryID = @CategoryID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_DeleteCategory') AND type IN (N'P', N'PC')))
	DROP PROCEDURE dbo.Articles_DeleteCategory
GO
CREATE PROCEDURE dbo.Articles_DeleteCategory
	@CategoryID		INT 
AS
BEGIN
	DECLARE @TranStarted	INT 
		SET @TranStarted  = 0
	
	IF(@@TRANCOUNT = 0)
	BEGIN
		BEGIN TRANSACTION
		SET @TranStarted = 1
	END
	ELSE
		SET @TranStarted = 0
	
	DECLARE @LocationId		INT 
	
	-- Before delete action occurs, must check sub-categories's and images's existence in that category.
	IF(EXISTS(SELECT ArticleCategoryID FROM ArticleCategories WHERE ParentArticleCategoryID = @CategoryID))
	BEGIN
		DELETE Articles WHERE ArticleCategoryId IN (SELECT ArticleCategoryID FROM ArticleCategories WHERE ParentArticleCategoryID = @CategoryID)
		IF (@@ERROR <> 0) GOTO CleanUp
		DELETE ArticleCategories WHERE ArticleCategoryID IN (SELECT ArticleCategoryID FROM ArticleCategories WHERE ParentArticleCategoryID = @CategoryID)
		IF(@@ERROR <> 0) GOTO CleanUP
	END
		-- First of all , Remove relative location
	DELETE Articles WHERE ArticleCategoryId = @CategoryID
	IF (@@ERROR <> 0) GOTO CleanUp
	DELETE ArticleCategories WHERE ArticleCategoryID = @CategoryID
	IF (@@ERROR <> 0) GOTO CleanUp
	
	IF(@TranStarted = 1)
	BEGIN
		COMMIT TRANSACTION
		SET @TranStarted = 0
	END
	RETURN 1
CleanUp:
	IF(@TranStarted = 1)
	BEGIN
		SET @TranStarted = 0
		ROLLBACK TRANSACTION
	END
	RETURN @@ERROR
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetArticles') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetArticles
GO

CREATE PROCEDURE [dbo].Articles_GetArticles
(
	@PageIndex		INT ,
	@PageSize		INT 
)
AS
BEGIN
	DECLARE @PageLowerBound INT 
    DECLARE @PageUpperBound INT 

    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

	CREATE TABLE #PageIndexForArticles
	(
		IndexId		INT IDENTITY(0,1) NOT NULL,
		ArticleID	VARCHAR(15)
	)

	INSERT INTO #PageIndexForArticles(ArticleID) 
		SELECT ArticleCategoryId FROM Articles ORDER BY AddedDate DESC

	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), 
			a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM #PageIndexForArticles p
		INNER JOIN Articles a ON p.ArticleID = a.ArticleID
	WHERE p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetRelatedPublishedArticles') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetRelatedPublishedArticles
GO

CREATE PROCEDURE [dbo].Articles_GetRelatedPublishedArticles
(
	@ArticleID		INT ,
	@CurrentDate	DATETIME,
	@CategoryID		INT,
	@ResultCount	INT 
)
AS
BEGIN
	DECLARE @ReleaseDate	DATETIME
		SELECT @ReleaseDate = ReleaseDate FROM Articles WHERE ArticleID = @ArticleID AND Approved = 1
		
	DECLARE @Mod	INT
		SET @Mod = @ResultCount % 2
	DECLARE @Upper	INT
		SET @Upper = @ResultCount / 2
		
	IF(@Mod = 1) SET @Upper = @Upper + 1
	DECLARE @Lower	INT
		SET @Lower = @ResultCount - @Upper
	
	-- Gioi han tren
	SET ROWCOUNT	@Upper
	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM Articles a
	WHERE 
			ArticleCategoryId = @CategoryID
		AND a.Approved = 1
		AND ReleaseDate <= @ReleaseDate 
		AND [ExpireDate] >= @CurrentDate
		AND	a.ArticleID <> @ArticleID
	ORDER BY a.AddedDate DESC
	
	-- Gioi han duoi
	SET ROWCOUNT	@Lower
	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM Articles a
	WHERE 
			ArticleCategoryId = @CategoryID
		AND a.Approved = 1
		AND ReleaseDate > @ReleaseDate 
		AND [ExpireDate] >= @CurrentDate
		AND	a.ArticleID <> @ArticleID
	ORDER BY a.AddedDate DESC
	
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetArticlesByCategory') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetArticlesByCategory
GO
CREATE PROCEDURE [dbo].Articles_GetArticlesByCategory
(
	@CategoryID		INT ,
	@PageIndex		INT ,
	@PageSize		INT 
)
AS
BEGIN
	DECLARE @PageLowerBound INT 
    DECLARE @PageUpperBound INT 

    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

	CREATE TABLE #PageIndexForArticles
	(
		IndexId		INT IDENTITY(0,1) NOT NULL,
		ArticleID	VARCHAR(15)
	)

	INSERT INTO #PageIndexForArticles(ArticleID) 
		SELECT ArticleID FROM Articles	WHERE ArticleCategoryId = @CategoryID ORDER BY AddedDate DESC

	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM #PageIndexForArticles p
		INNER JOIN Articles a ON p.ArticleID = a.ArticleID
	WHERE p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetPublishedArticles') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetPublishedArticles
GO
CREATE PROCEDURE [dbo].Articles_GetPublishedArticles
(
	@CurrentDate		DATETIME,
	@PageIndex			INT ,
	@PageSize			INT 
)
AS
BEGIN
	DECLARE @PageLowerBound INT 
    DECLARE @PageUpperBound INT 

    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

	CREATE TABLE #PageIndexForArticles
	(
		IndexId		INT IDENTITY(0,1) NOT NULL,
		ArticleID	VARCHAR(15)
	)

	INSERT INTO #PageIndexForArticles(ArticleID) 
		SELECT ArticleID FROM Articles	WHERE Approved = 1 AND Listed = 1 AND ReleaseDate <= @CurrentDate AND ExpireDate >= @CurrentDate ORDER BY AddedDate DESC

	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM #PageIndexForArticles p
		INNER JOIN Articles a ON p.ArticleID = a.ArticleID
	WHERE p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetPublishedArticlesByCategory') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetPublishedArticlesByCategory
GO
CREATE PROCEDURE [dbo].Articles_GetPublishedArticlesByCategory
(
	@CategoryID			INT ,
	@CurrentDate		DATETIME,
	@PageIndex			INT ,
	@PageSize			INT 
)
AS
BEGIN
	DECLARE @PageLowerBound INT 
    DECLARE @PageUpperBound INT 

    SET @PageLowerBound = @PageSize * @PageIndex
    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

	CREATE TABLE #PageIndexForArticles
	(
		IndexId		INT IDENTITY(0,1) NOT NULL,
		ArticleID	VARCHAR(15)
	)

	INSERT INTO #PageIndexForArticles(ArticleID) 
		SELECT ArticleID FROM Articles	WHERE Approved = 1 AND Listed = 1 AND ArticleCategoryId = @CategoryID AND ReleaseDate <= @CurrentDate AND ExpireDate >= @CurrentDate ORDER BY AddedDate DESC

	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM #PageIndexForArticles p
		INNER JOIN Articles a ON p.ArticleID = a.ArticleID
	WHERE p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetArticle') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetArticle
GO
CREATE PROCEDURE [dbo].Articles_GetArticle
(
	@ArticleID	VARCHAR(15)
)
AS
BEGIN
	SELECT a.ArticleID, a.ArticleCategoryId, 'CategoryTitle' = dbo.Articles_GetCategoryTitle(a.ArticleCategoryId), a.AddedDate, a.ReleaseDate, a.ExpireDate, a.AddedByName, a.Title, 
			a.Abstract, 'Body' = N'', a.ImageUrl, a.Approved, a.Listed, a.CommentsEnabled, a.OnlyForMembers, a.ViewCount
	FROM Articles a
	WHERE a.ArticleID = @ArticleID 
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetArticleBody') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetArticleBody
GO
CREATE PROCEDURE [dbo].Articles_GetArticleBody
(
	@ArticleID		varchar(15),
	@IsPlainBody	bit
)
AS
BEGIN
	if(@IsPlainBody = 1)SELECT PlainBody FROM dbo.Articles WHERE ArticleID = @ArticleID
	else
	SELECT Body FROM dbo.Articles WHERE ArticleID = @ArticleID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetArticleCount') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetArticleCount
GO
CREATE PROCEDURE [dbo].Articles_GetArticleCount
AS
BEGIN
	SELECT COUNT(*) FROM Articles
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetArticleCountByCategory') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetArticleCountByCategory
GO
CREATE PROCEDURE [dbo].Articles_GetArticleCountByCategory
(
	@CategoryID		INT 
)
AS
BEGIN
	SELECT COUNT(*) FROM Articles WHERE ArticleCategoryId = @CategoryID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetPublishedArticleCount') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetPublishedArticleCount
GO
CREATE PROCEDURE [dbo].Articles_GetPublishedArticleCount
(
	@CurrentDate		DATETIME
)
AS
BEGIN
	SELECT COUNT(*) FROM Articles
	WHERE	ReleaseDate <= @CurrentDate AND ExpireDate > @CurrentDate
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_GetPublishedArticleCountByCategory') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_GetPublishedArticleCountByCategory
GO
CREATE PROCEDURE [dbo].Articles_GetPublishedArticleCountByCategory
(
	@CategoryID			INT ,
	@CurrentDate		DATETIME
)
AS
BEGIN
	SELECT COUNT(*) FROM Articles
	WHERE ArticleCategoryId = @CategoryID AND ReleaseDate <= @CurrentDate AND ExpireDate >= @CurrentDate
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_ApproveArticle') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_ApproveArticle
GO
CREATE PROCEDURE dbo.Articles_ApproveArticle
(
	@ArticleID		INT 
)
AS
BEGIN
	UPDATE Articles SET Approved = 1 WHERE ArticleID = @ArticleID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.NV_Articles_IncrementViewCount') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.NV_Articles_IncrementViewCount
GO
CREATE PROCEDURE dbo.NV_Articles_IncrementViewCount
(
	@ArticleID		INT 
)
AS
BEGIN
	UPDATE Articles SET ViewCount = ViewCount + 1 WHERE ArticleID = @ArticleID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_InsertArticle') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_InsertArticle
GO
CREATE PROCEDURE [dbo].Articles_InsertArticle
(
	@ArticleID			varchar(15),
	@AddedDate			DATETIME,
	@ReleaseDate		DATETIME,
	@ExpireDate			DATETIME,
	@AddedByName		nvarchar(256),
	@CategoryID			INT ,
	@BaseName			nvarchar(256),
	@Title				nvarchar(256),
	@Abstract			nvarchar(4000),
	@ImageUrl			nvarchar(256),
	@PlainBody			ntext,
	@Body				ntext,
	@Approved			bit = 0,
	@Listed				bit = 0,
	@CommentsEnabled	bit = 0,
	@OnlyForMembers		bit = 0
)
AS
BEGIN
	IF (NOT EXISTS( SELECT ArticleCategoryID FROM ArticleCategories WHERE ArticleCategoryID = @CategoryID ))
		RETURN -1
	IF (EXISTS(SELECT * FROM Articles WHERE ArticleID = @ArticleID)) RETURN -1

	INSERT Articles(ArticleID, AddedDate, ReleaseDate, ExpireDate, AddedByName, ArticleCategoryId, Title, Abstract, ImageUrl, PlainBody, Body, Approved, Listed, CommentsEnabled, OnlyForMembers)
	VALUES (@ArticleID, @AddedDate, @ReleaseDate, @ExpireDate, @AddedByName, @CategoryID, @BaseName, @Title, @Abstract, @ImageUrl, @PlainBody, @Body, @Approved, @Listed, @CommentsEnabled, @OnlyForMembers)
	
	RETURN @@identity
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Articles_UpdateArticle') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Articles_UpdateArticle
GO
CREATE PROCEDURE [dbo].Articles_UpdateArticle
(
	@ArticleID			varchar(15),
	@ReleaseDate		DATETIME,
	@ExpireDate			DATETIME,
	@CategoryID			INT ,
	@BaseName			nvarchar(256),
	@Title				nvarchar(256),
	@Abstract			nvarchar(4000),
	@ImageUrl			nvarchar(250),
	@PlainBody			ntext,
	@Body				ntext,
	@Approved			bit,
	@Listed				bit,
	@CommentsEnabled	bit,
	@OnlyForMembers		bit
)
AS
BEGIN
	UPDATE Articles
	SET
		ReleaseDate		= @ReleaseDate,
		ExpireDate		= @ExpireDate,
		ArticleCategoryId		= @CategoryID,	
		Title			= @Title,	
		Abstract		= @Abstract,
		ImageUrl		= @ImageUrl,
		PlainBody		= @PlainBody,
		Body			= @Body,
		Approved		= @Approved,
		Listed			= @Listed,
		CommentsEnabled	= @CommentsEnabled,
		OnlyForMembers	= @OnlyForMembers
	WHERE ArticleID = @ArticleID
END
GO

IF(EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.Article_DeleteArticle') AND type IN (N'P',N'PC')))
	DROP PROCEDURE dbo.Article_DeleteArticle
GO
CREATE PROCEDURE [dbo].Article_DeleteArticle
(
	@ArticleID		varchar(15)
)
AS
BEGIN
	DELETE Articles WHERE ArticleID = @ArticleID
END
GO